POV-Ray : Newsgroups : povray.beta-test : Function weirdness : Re: Function weirdness Server Time
4 Nov 2024 23:16:16 EST (-0500)
  Re: Function weirdness  
From: Thorsten Froehlich
Date: 19 Sep 2001 11:45:39
Message: <3ba8bda3@news.povray.org>

Skiba <abx### [at] babilonorg>  wrote:

> #declare MyFunc=function(x,y,z){
>   #local A=x+y+z;
>   #local B=max3(x,y,z);
>   (A*x/B)+(A*y/B)+(A*z/B)
> } // I don't know what's this expression feel free to test
>
> this can't work, but you can replace this with two declarations
>
> #declare WithLocals=function(x,y,z,A,B){
>   (A*x/B)+(A*y/B)+(A*z/B)
> }
> #declare MyFunc=function(x,y,z){WithLocals(x,y,z,x+y+z,max3(x,y,z))}
>
> I don't know 3.5 engine yet but I think it causes one calculation of
> such local variables.

While this should work, I would only recommend it for really complex cases
(more than 20 or so operators) because function calls are in many cases more
"expensive" than just calculating the value over and over again (which can
be optimised, btw).

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.